package com.cj.picturebackend.exception;

import com.cj.picturebackend.common.BaseResponse;
import com.cj.picturebackend.common.ResultUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author cc
 * @date 2025-04-06 21:05
 **/
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {



    @ExceptionHandler(BusinessException.class)
    public BaseResponse<?> businessExceptionHandler(BusinessException e){
        log.error("业务异常：{}",e.getMessage());
        return ResultUtils.error(e.getCode(),e.getMessage());
    }


    @ExceptionHandler(RuntimeException.class)
    public BaseResponse<?> businessExceptionHandler(RuntimeException e){
        log.error("runtimeException：{}",e.getMessage());
        return ResultUtils.error(ErrorCode.SYSTEM_ERROR,"系统错误");
    }
}
